package com.tourism.website.personal.controller;


import com.tourism.website.apis.PersonalApis;
import com.tourism.website.personal.service.IUserService;
import com.tourismwebsite.personal.dto.PersonalDTO;
import com.tourismwebsite.personal.query.PersonalQuery;
import com.tourismwebsite.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.sound.midi.Soundbank;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kevin
 * @since 2024-06-11
 */
@RestController
@RequestMapping("/personal")
@Api(tags = "个人信息管理模块")
@Validated
public class UserController implements PersonalApis {
    @Resource
    IUserService iUserService;

    //修改个人信息
    @PostMapping("update-personal")
    @ApiOperation(value = "修改用户个人信息")
    @Override
    public JsonVO<Boolean> updatePersonal(PersonalQuery personalQuery) {
        boolean result = iUserService.updatePersonal(personalQuery);
        if(result){
            JsonVO.create(null,10000,"修改成功");
        }
            return JsonVO.fail(null);
    }
    //查询个人信息
    @GetMapping("query-personal")
    @ApiOperation(value = "根据用户名查询用户个人信息")
    @Override
    public JsonVO<List<PersonalDTO>> queryPersonal(@RequestParam String userName) {
        return JsonVO.success(iUserService.queryPersonal(userName));
    }

    @GetMapping("query-personal-ById")
    @ApiOperation(value = "根据用户ID查询用户个人信息")
    @Override
    public JsonVO<List<PersonalDTO>> queryPersonalById(Integer userId) {
        return JsonVO.success(iUserService.queryPersonalById(userId));
    }
}

